﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class sites_Customer : System.Web.UI.Page
{
    private webServiceReference.IFlightCaseService wsr;
    private int customerNo;
    protected void Page_Load(object sender, EventArgs e)
    {
        wsr = new webServiceReference.FlightCaseServiceClient();
        customerNo = 0;
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        string fName = txtFirst.Text;
        string lName = txtLast.Text;
        string address = txtAdr.Text;
        int postalCode = 0;
        try
        {
            postalCode = Convert.ToInt32(txtPost.Text);
            string phone = txtPhoNr.Text;
            string email = txtMail.Text;
            if (fName != "" && lName != "" && address != "" && phone != "" && email != "")
            {
                if (postalCode > 999)
                {
                    customerNo = wsr.CreateCustomer(fName, lName, address, postalCode, phone, email);
                    //lblCustomerNo.Text = "Customer: " + fName + " " + lName;
                    //lblCustomerSuccess.Text = "Customer registered successfully!";
                }
                else
                {
                    //MessageBox.Show("Postal code must be at least 4 digits long");
                }
            }
            else
            {
                //MessageBox.Show("No fields can be empty");
            }
        }
        catch (FormatException ConversionFormatException)
        {
            //MessageBox.Show("Postal code must be a possitive number");
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //ResetrtbCustomerInfo();
        string phoneNo = txtSearchPhone.Text;
        //Flight_Reservation.DataLayer.Customer customer = wsr.FindCustomerByPhone(phoneNo);
        //if (customer.CustomerNo != 0)
        //{
        //    rtbCustomerInfo.Text = "Customer Number: " + customer.CustomerNo + Environment.NewLine;
        //    rtbCustomerInfo.Text += "First name: " + customer.FName + Environment.NewLine;
        //    rtbCustomerInfo.Text += "Last name: " + customer.LName + Environment.NewLine;
        //    rtbCustomerInfo.Text += "Address: " + customer.Address + Environment.NewLine;
        //    rtbCustomerInfo.Text += "Postal Code: " + customer.PostalCode + Environment.NewLine;
        //    rtbCustomerInfo.Text += "Phone Number: " + customer.PhoneNo + Environment.NewLine;
        //    rtbCustomerInfo.Text += "Email: " + customer.Email + Environment.NewLine;

        //    customerNo = customer.CustomerNo;
        //    if (customerNo > 0)
        //    {
        //        lblCustomerNo.ForeColor = System.Drawing.Color.Black;
        //    }
        //    lblCustomerNo.Text = "Customer: " + customer.FName + " " + customer.LName;
        //}
        //else
        //{
        //    MessageBox.Show("No customer with the given phone number was found");
        //}
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Resavertion.aspx");
        //ClearReservationTab();
    }
}